package com.tmt.im.manager.controller.api;

import com.tmt.im.manager.controller.vo.PersonalSettingVo;
import com.tmt.im.manager.service.IMUserService;
import com.tmt.springboot.common.restful.IExecuteResult;
import com.tmt.springboot.common.restful.ResultWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.concurrent.CompletableFuture;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/10/11 13:11
 * @Version 1.0
 **/
@Async("asyncTaskExecutor")
@Tag(name = "个人设置相关接口", description = "个人设置相关接口")
@RestController
@RequestMapping("${api-url-prefix}/personalSetting")
public class PersonalSettingController {

    private final IMUserService imUserService;

    public PersonalSettingController(IMUserService imUserService) {
        this.imUserService = imUserService;
    }

    @Operation(summary = "查询用户个人参数配置",
            description = "查询用户个人参数配置",
            operationId = "getPersonalSetting")
    @GetMapping(value = "/query")
    public CompletableFuture<IExecuteResult<PersonalSettingVo>> getPersonalSetting(Principal principal) {
        IExecuteResult<PersonalSettingVo> result = imUserService.getPersonalSetting(principal);
        return CompletableFuture.completedFuture(result);
    }

    @Operation(summary = "修改用户个人参数配置",
            description = "修改用户个人参数配置",
            operationId = "updatePersonalSetting",
            parameters = {
                    @Parameter(name = "settingVo", description = "个人参数配置对象", required = true)
            })
    @PostMapping(value = "/update")
    public CompletableFuture<IExecuteResult<ResultWrapper<Boolean>>> updatePersonalSetting(@RequestBody PersonalSettingVo settingVo, Principal principal) {
        IExecuteResult<Boolean> result = imUserService.updatePersonalSetting(settingVo, principal);
        return CompletableFuture.completedFuture(ResultWrapper.from(result));
    }
}
